package com.fastjars.business.shiro.model;

import com.fastjars.business.spring.resolver.tree.BaseTree;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;

/**
 * Menu
 * 菜单
 * @author Brant Liu <br> 邮箱：<br>lbf1988@qq.com <br>日期：<br>2018/06/05
 * @version 1.0.0
 */
public class Menu extends BaseTree<Menu, Integer> implements Serializable,Cloneable {
    /**
     * 编号
     */
    private Integer id;
    /**
     * 父级编号
     */
    private Integer parentId;
    /**
     * 权限
     */
    private String permission;
    /**
     * 菜单名称
     */
    private String name;
    /**
     * 图标
     */
    private String icon;
    /**
     * 跳转地址
     */
    private String url;

    @Override
    public Integer getId() {
        return id;
    }

    @Override
    public void setId(Integer id) {
        this.id = id;
    }

    @Override
    public Integer getParentId() {
        return parentId;
    }

    @Override
    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public boolean isChildrenUrl(String url){
        boolean flag = false;
        if(!CollectionUtils.isEmpty(this.getChildren())){
            for(Menu menu:this.getChildren()){
                if(menu.getUrl().equals(url)){
                    flag = true;
                    menu.setChecked(true);
                }else{
                    menu.setChecked(false);
                }
            }
        }
        return flag;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        Menu newPermission = (Menu) super.clone();
        newPermission.setId(null);
        return newPermission;
    }
}
